//
//  FunStudyViewController.swift
//  test_swift
//
//  Created by fangyuan ding on 2021/5/31.
//

import UIKit

class FunStudyViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print(runoob(site: "www.runoob.com"))
        
        print(runoob(name: "菜鸟教程：", site: "www.runoob.com"))
        print(runoob(name: "Google：", site: "www.google.com"))
        
        let bounds = minMax(array: [8, -6, 2, 109, 3, 71])
        print("最小值为 \(bounds.min) ，最大值为 \(bounds.max)")
//        var addition: (Int, Int) -> Int = sum
//        print("输出结果: \(addition(40, 89))")
        
        var addition: (Int, Int) -> Int = sum
        print("输出结果: \(addition(40, 89))")
        another(addition: sum, a: 10, b: 20)
        
        let decrem = calcDecrement(forDecrement: 30)
        print(decrem())
      
    }
    
    func runoob(site: String) -> String {
        return (site)
    }
    func runoob(name: String, site: String) -> String {
        return name + site
    }
    
    func minMax(array: [Int]) -> (min: Int, max: Int) {
        var currentMin = array[0]
        var currentMax = array[0]
        for value in array[1..<array.count] {
            if value < currentMin {
                currentMin = value
            } else if value > currentMax {
                currentMax = value
            }
        }
        return (currentMin, currentMax)
    }
    func sum(a: Int, b: Int) -> Int {
        return a + b
    }
  

    func another(addition: (Int, Int) -> Int, a: Int, b: Int) {
        print("输出结果: \(addition(a, b))")
    }
    
    func calcDecrement(forDecrement total: Int) -> () -> Int {
       var overallDecrement = 0
       func decrementer() -> Int {
          overallDecrement -= total
          return overallDecrement
       }
       return decrementer
    }
}
